package cn.com.niit.controller;

import cn.com.niit.pojo.Bill;
import cn.com.niit.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class BillController {
    @Autowired
    BillService billService;
    @RequestMapping("/addBill")
    public void addBill(Bill bill, String p){
        bill.setStatus(0);
        bill.setPrice(Double.parseDouble(p));
        billService.addBill(bill);
    }
    @RequestMapping("/delBill")
    public void delBill(String id){
        billService.delBill(Integer.parseInt(id));
    }
    @RequestMapping("/showPayBill")
    public List<Bill> showPayBill(String shopUserName, String userName){
        return   billService.findBill(shopUserName,userName,1);
    }
    @RequestMapping("/showNoPayBill")
    public List<Bill>  showNoPayBill(String shopUserName,String userName){
        return billService.findBill(shopUserName,userName,0);
    }
        @RequestMapping("/showAllBill")
    public List<Bill> showAllBill(Bill bill,String p){
        if (p!=null &&!p.equals(""))
            bill.setPrice(Double.parseDouble(p));
        return billService.searchBill(bill);
    }
}
